package com.anjho.pojo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "profile")
@NamedQueries(value = {
		@NamedQuery(name = "Profile.getProfileList", query = "SELECT p FROM Profile p"),
		@NamedQuery(name = "Profile.getProfileByProCode", query = "SELECT p FROM Profile p WHERE p.procode = :procode")
})
public class Profile implements Serializable {
	
	private static final long serialVersionUID = 545010527182510542L;

	public Profile(){
		this.setPages(new ArrayList<Page>());
	}

	@Id
	@Column(name = "procode")
	@OneToMany(mappedBy = "profile", cascade= {CascadeType.PERSIST})
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	private int procode;

	@Column(name = "description", nullable = false, length = 50)
	private String description;

	@ManyToMany
	@JoinTable(name = "profile_pages", joinColumns = { @JoinColumn(name = "procode") }, inverseJoinColumns = { @JoinColumn(name = "pacode") })
	private List<Page> pages;

	public int getProcode() {
		return procode;
	}

	public void setProcode(int procode) {
		this.procode = procode;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public List<Page> getPages(){
		return this.pages;
	}
	
	public void setPages(List<Page> pages){
		this.pages = pages;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + procode;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Profile other = (Profile) obj;
		if (procode != other.procode)
			return false;
		return true;
	}

}
